package com.ccdt.tv.roundprogram.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ccdt.tv.roundprogram.R;
import com.ccdt.tv.roundprogram.bean.Channel;
import com.ccdt.tv.roundprogram.view.custom.SelectedRelativeLayout;

import java.util.List;

/**
 * create by hfq 2018/10/22
 */
public class ProgramAdapter extends BaseAdapter {

    private Context mContext;
    private List<Channel> mChannelList;

    public ProgramAdapter(List<Channel> channelList, Context context) {
        this.mChannelList = channelList;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mChannelList == null ? 0 : mChannelList.size();
    }

    @Override
    public Object getItem(int position) {
        return mChannelList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_program, parent, false);
            holder = new ViewHolder();
            holder.tv_name = view.findViewById(R.id.tv_name);
            holder.rv_group = view.findViewById(R.id.rv_group);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        Channel channel = mChannelList.get(position);
        holder.tv_name.setText(channel.getChannelName());
        return view;
    }

    private class ViewHolder {
        TextView tv_name;
        SelectedRelativeLayout rv_group;
    }
}
